package org.example;

import java.math.BigDecimal;

public class FruitFactory {

    public static Fruit createFruit(FruitEnum type) {
        return switch (type) {
            case APPLE -> new Apple(type.getName(), type.getPrice(), type.getDiscount());
            case STRAWBERRY -> new Strawberry(type.getName(), type.getPrice(), type.getDiscount());
            case MANGO -> new Mango(type.getName(), type.getPrice(), type.getDiscount());
            default -> throw new IllegalArgumentException("不支持的水果类型: " + type);
        };
    }

    public static Fruit createFruit(FruitEnum type, BigDecimal discount) {
        return switch (type) {
            case APPLE -> new Apple(type.getName(), type.getPrice(), discount);
            case STRAWBERRY -> new Strawberry(type.getName(), type.getPrice(), discount);
            case MANGO -> new Mango(type.getName(), type.getPrice(), discount);
            default -> throw new IllegalArgumentException("不支持的水果类型: " + type);
        };
    }

}